Thread: [C] Problem with icons in a toolbar

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    49
    salutations,

    we are beginners. we are trying to create a toolbar with icons both from the Common Controls standard icons (STD_FILENEW, etc.) and from an imagelist that contains self-made icons. we are using this code (based on MSDN and www.winprog.org/tutorial/).
    NOTE: we are including the rest of the WinMain for clarity as to what is b.

    Code:
    _stdcall WinMain(HINSTANCE i, HINSTANCE j, char *k, int l) 
    { 
       InitCommonControls();
       LoadLibrary("Riched32.dll");
       b=CreateDialog(i,(LPCTSTR)"DIALOGO",NULL,(DLGPROC)zzz);
    
       HWND hTool = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD | WS_VISIBLE, 0, 0, 0, 0, b, (HMENU)45/*ID*/, GetModuleHandle(NULL), NULL);
       SendMessage(hTool, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
       TBBUTTON tbb[3];
    
        HIMAGELIST hImageList = ImageList_Create(
            16, 16,                   // Dimensions of individual bitmaps.  
            ILC_COLOR16 | ILC_MASK,   // Ensures transparent background.
            sizeof(tbb)/sizeof(TBBUTTON), 0);
    	int custom_icon = ImageList_AddIcon(hImageList, LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDR_ICO_MAIN)));
    	SendMessage(hTool, TB_SETIMAGELIST, 0, (LPARAM)hImageList);
    
    	SendMessage(hTool, TB_LOADIMAGES, (WPARAM)IDB_STD_SMALL_COLOR, (LPARAM)HINST_COMMCTRL);
    
    	ZeroMemory(tbb, sizeof(tbb));
       tbb[0].iBitmap = STD_FILENEW;
       tbb[0].fsState = TBSTATE_ENABLED;
       tbb[0].fsStyle = TBSTYLE_BUTTON;
       tbb[0].idCommand = 6002;
    
       tbb[1].iBitmap = STD_FILEOPEN;
       tbb[1].fsState = TBSTATE_ENABLED;
       tbb[1].fsStyle = TBSTYLE_BUTTON;
       tbb[1].idCommand = 6001;
    
       tbb[2].iBitmap = custom_icon;
       tbb[2].fsState = TBSTATE_ENABLED;
       tbb[2].fsStyle = TBSTYLE_BUTTON | TBSTYLE_DROPDOWN;
       tbb[2].idCommand = 453;
    
       SendMessage(b, WM_SIZE, 0, 0);
       ShowWindow(b,SW_SHOW);
    
       while (GetMessage(&c,0,0,0)==TRUE)
       {
    	  TranslateMessage(&c); 
          DispatchMessage(&c);
       }
    }
    notice that there is both the loading of an icon in an imagelist and its loading into the toolbar, as well as SendMessage(hTool, TB_LOADIMAGES, (WPARAM)IDB_STD_SMALL_COLOR, (LPARAM)HINST_COMMCTRL); for the loading of the common control icons. the strange thing is that the button that was supposed to display STD_FILENEW displays STD_DELETE instead. when only the common control icons - and not the icons from the imagelist - are loaded into the toolbar, STD_FILENEW is displayed correctly.
    what is wrong with this code? is there a more proper way?

    thank you in advance.
    Last edited by pc2-brazil; 12-21-2008 at 05:47 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Toolbar problem
    By mrafcho001 in forum Windows Programming
    Replies: 2
    Last Post: 12-27-2005, 11:38 AM
  2. Toolbar problem
    By Ward in forum Windows Programming
    Replies: 0
    Last Post: 12-21-2005, 03:08 PM
  3. Dockable Toolbar (Like taskbar or office toolbar)
    By om3ga in forum Windows Programming
    Replies: 2
    Last Post: 11-20-2005, 03:09 AM
  4. Troubles with ListView and Toolbar
    By cornholio in forum Windows Programming
    Replies: 8
    Last Post: 11-14-2005, 01:26 AM
  5. Replies: 5
    Last Post: 11-07-2005, 11:34 PM